package com.cadre.system.olddomain;

import com.cadre.common.utils.DateUtil;
import com.cadre.system.domain.officer.A19;
import org.apache.commons.lang3.time.DateUtils;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/* loaded from: ResumeParse.class */
public class ResumeParse {
    private static final String REGEX_DUNHAO = "、";
    private static final String REGEX_DOUHAO = ",";
    private static ResumeParse instance;
    private String operateString;
    private String remark;
    private String startDate;
    private String endDate;
    private Segment segment = new Segment(0);
    private Segment childUnitSegment = new Segment(1);
    private List<A19> returnList;

    private ResumeParse() {
    }

    public static ResumeParse getInstance() {
        if (instance == null) {
            instance = new ResumeParse();
        }
        return instance;
    }

    public List<A19> parseResume(String str) throws ParseException {
        this.returnList = new ArrayList();
        for (String item : str.split("\\n(?=[\\d])")) {
            formatResume(item);
            setRemark();
            setWorkTimeQuantum();
            setUnitAndPost();
        }
        return this.returnList;
    }

    private void formatResume(String str) {
        this.operateString = str.replaceAll("\\s*", "").replaceAll("（", "(").replaceAll("）", ")").replaceAll("，", REGEX_DOUHAO).replace("(兼)", "").replace("(市、区)", "(市.区)").replaceAll("兼", REGEX_DUNHAO).replace("　", "");
    }

    private void setRemark() {
        this.remark = "";
        if (this.operateString.contains("(")) {
            StringBuilder sb = new StringBuilder();
            ArrayList<String> word = new ArrayList<>();
            int m = 0;
            int count = 0;
            for (int i = 0; i < this.operateString.length(); i++) {
                if (this.operateString.charAt(i) == '(') {
                    if (count == 0) {
                        m = i;
                    }
                    count++;
                }
                if (this.operateString.charAt(i) == ')') {
                    count--;
                    if (count == 0 && i == this.operateString.length() - 1) {
                        word.add(this.operateString.substring(m, i + 1));
                        System.out.println("位置:" + i + ",长度" + this.operateString.length() + ",括号字符串：" + this.operateString.substring(m, i + 1));
                    }
                }
            }
            for (int l = 0; l < word.size(); l++) {
                String a = word.get(l);
                if (a.length() > 6) {
                    this.operateString = this.operateString.replace(a, "");
                    try {
                        if (a.charAt(0) == '(') {
                            a = a.substring(1);
                        }
                        if (a.charAt(a.length() - 1) == ')') {
                            a = a.substring(0, a.length() - 1);
                        }
                        if (word.size() == 1) {
                            sb.append(a.trim());
                        } else {
                            sb.append(a.trim() + ";");
                        }
                    } catch (Exception e) {
                        sb.append(a + ";");
                    }
                }
            }
            this.remark = sb.toString();
        }
    }

    private void setWorkTimeQuantum() {
        Matcher matcher = Pattern.compile("(\\d{0,4}\\.(\\d{0,2})(--)([\\d\\.]*))").matcher(this.operateString);
        String strtime = "";
        while (matcher.find()) {
            strtime = matcher.group();
        }
        String[] workDateQuantum = strtime.split("--");
        if (workDateQuantum.length == 1) {
            workDateQuantum = new String[]{workDateQuantum[0], ""};
        }
        this.startDate = workDateQuantum[0];
        this.endDate = workDateQuantum[1];
        this.operateString = matcher.replaceAll("");
    }

    private void setUnitAndPost() throws ParseException {
        if (this.operateString.contains(REGEX_DOUHAO)) {
            for (String item : this.operateString.split(REGEX_DOUHAO)) {
                this.returnList.addAll(buildResume(item));
            }
            return;
        }
        this.returnList.addAll(buildResume(this.operateString));
    }

    private List<A19> buildResume(String str) throws ParseException {
        List<A19> list = new ArrayList<>();
        if (str.contains(REGEX_DUNHAO)) {
            String[] items = str.split(REGEX_DUNHAO);
            String strKH = "";
            if (items[0].endsWith(")")) {
                ArrayList<String> word = new ArrayList<>();
                int m = 0;
                int count = 0;
                for (int i = 0; i < items[0].length(); i++) {
                    if (items[0].charAt(i) == '(') {
                        if (count == 0) {
                            m = i;
                        }
                        count++;
                    }
                    if (items[0].charAt(i) == ')') {
                        count--;
                        if (count == 0) {
                            word.add(items[0].substring(m, i + 1));
                        }
                    }
                }
                for (int w = 0; w < word.size(); w++) {
                    if (w == word.size() - 1) {
                        strKH = word.get(w);
                        items[0] = items[0].replace(word.get(w), "");
                    }
                }
            }
            String[] unitAndPost = this.segment.segmentPostUnit(items[0]);
            String[] units = this.childUnitSegment.segmentUnit(unitAndPost[0].trim());
            String post = unitAndPost[1].trim() + strKH;
            for (int i2 = 0; i2 < items.length; i2++) {
                if (i2 != 0) {
                    post = items[i2];
                }
                A19 resume = new A19();
                resume.setRemark(this.remark);
                try {
                    resume.setA1905(DateUtils.parseDate(this.startDate, new String[]{DateUtil.MONTG_DATE_FORMAT}));
                } catch (Exception ex) {
                    System.out.println("parse start-date error:" + ex.getMessage());
                }
                try {
                    resume.setA1910(DateUtils.parseDate(this.endDate, new String[]{DateUtil.MONTG_DATE_FORMAT}));
                } catch (Exception ex2) {
                    System.out.println("parse end-date error:" + ex2.getMessage());
                }
                resume.setA1916(units[0]);
                resume.setA1965(units[1]);
                resume.setA1920(post);
                list.add(resume);
            }
            return list;
        }
        String strKH2 = "";
        if (str.endsWith(")")) {
            ArrayList<String> word2 = new ArrayList<>();
            int m2 = 0;
            int count2 = 0;
            for (int i3 = 0; i3 < str.length(); i3++) {
                if (str.charAt(i3) == '(') {
                    if (count2 == 0) {
                        m2 = i3;
                    }
                    count2++;
                }
                if (str.charAt(i3) == ')') {
                    count2--;
                    if (count2 == 0) {
                        word2.add(str.substring(m2, i3 + 1));
                    }
                }
            }
            for (int w2 = 0; w2 < word2.size(); w2++) {
                if (w2 == word2.size() - 1) {
                    strKH2 = word2.get(w2);
                    str = str.replace(word2.get(w2), "");
                }
            }
        }
        String[] unitAndPost2 = this.segment.segmentPostUnit(str);
        String[] units2 = this.childUnitSegment.segmentUnit(unitAndPost2[0].trim());
        String post2 = (unitAndPost2[1] + strKH2).trim();
        A19 resume2 = new A19();
        resume2.setRemark(this.remark);
        try {
            resume2.setA1905(DateUtils.parseDate(this.startDate, new String[]{DateUtil.MONTG_DATE_FORMAT}));
        } catch (Exception ex3) {
            System.out.println("parse start-date error:" + ex3.getMessage());
        }
        try {
            resume2.setA1910(DateUtils.parseDate(this.endDate, new String[]{DateUtil.MONTG_DATE_FORMAT}));
        } catch (Exception ex4) {
            System.out.println("parse end-date error:" + ex4.getMessage());
        }
        resume2.setA1916(units2[0]);
        resume2.setA1965(units2[1]);
        resume2.setA1920(post2);
        list.add(resume2);
        return list;
    }
}
